1 using System;
2 using UnityEditor;
3 using UnityEngine;
4
5 namespace ProceduralToolkit.Editor
6 {
7 public class ProceduralToolkitMenu
8 {
9 public const string version = "0.1.9";
10
11 private const string primitivesPath = "GameObject/Procedural Toolkit/";
12 private const string create = "Create ";
13
14 private const int platonicSolids = 0;
15 private const string tetrahedron = "Tetrahedron";
16 private const string cube = "Cube";
17 private const string octahedron = "Octahedron";
18 private const string dodecahedron = "Dodecahedron";
19 private const string icosahedron = "Icosahedron";
20
21 private const int other = 20;
22 private const string plane = "Plane";
23 private const string pyramid = "Pyramid";
24 private const string prism = "Prism";
25 private const string cylinder = "Cylinder";
26 private const string sphere = "Sphere";
27
28 [MenuItem("Help/About Procedural Toolkit")]
29 private static void About()
30 {
31 AboutWindow.Open();
32 }
33
34 private static void PrimitiveTemplate(string name, Func<Mesh> mesh)
35 {
36 var go = GameObject.CreatePrimitive(PrimitiveType.Quad);
37 Undo.RegisterCreatedObjectUndo(go, create + name);
38 UnityEngine.Object.DestroyImmediate(go.GetComponent<Collider>());
39 go.name = name;
40 go.GetComponent<MeshFilter>().mesh = mesh();
41 }
42
43 #region Platonic solids
44
45 [MenuItem(primitivesPath + tetrahedron, false, platonicSolids + 0)]
46 public static void Tetrahedron()
47 {
48 PrimitiveTemplate(tetrahedron, () => MeshE.Tetrahedron(1));
49 }
50
51 [MenuItem(primitivesPath + cube, false, platonicSolids + 1)]
52 public static void Cube()
53 {
54 PrimitiveTemplate(cube, () => MeshE.Cube(1));
55 }
56
57 [MenuItem(primitivesPath + octahedron, false, platonicSolids + 2)]
58 public static void Octahedron()
59 {
60 PrimitiveTemplate(octahedron, () => MeshE.Octahedron(1));
61 }
62
63 [MenuItem(primitivesPath + dodecahedron, false, platonicSolids + 3)]
64 public static void Dodecahedron()
65 {
66 PrimitiveTemplate(dodecahedron, () => MeshE.Dodecahedron(1));
67 }
68
69 [MenuItem(primitivesPath + icosahedron, false, platonicSolids + 4)]
70 public static void Icosahedron()
71 {
72 PrimitiveTemplate(icosahedron, () => MeshE.Icosahedron(1));
73 }
74
75 #endregion Platonic solids
76
77 #region Other
78
79 [MenuItem(primitivesPath + plane, false, other + 0)]
80 public static void Plane()
81 {
82 PrimitiveTemplate(plane, () => MeshE.Plane(10, 10, 10, 10));
83 }
84
85 [MenuItem(primitivesPath + pyramid, false, other + 1)]
86 public static void Pyramid()
87 {
88 PrimitiveTemplate(pyramid, () => MeshE.Pyramid(1, 6, 1));
89 }
90
91 [MenuItem(primitivesPath + prism, false, other + 2)]
92 public static void Prism()
93 {
94 PrimitiveTemplate(prism, () => MeshE.Prism(1, 16, 1));
95 }
96
97 [MenuItem(primitivesPath + cylinder, false, other + 3)]
98 public static void Cylinder()
99 {
100 PrimitiveTemplate(cylinder, () => MeshE.Cylinder(1, 16, 1));
101 }
102
103 [MenuItem(primitivesPath + sphere, false, other + 4)]
104 public static void Sphere()
105 {
106 PrimitiveTemplate(sphere, () => MeshE.Sphere(1, 16, 16));
107 }
108
109 #endregion Other
110 }
111
112 public class AboutWindow : EditorWindow
113 {
114 public static void Open()
115 {
116 GetWindow<AboutWindow>(true, "About Procedural Toolkit");
117 }
118
119 private void OnGUI()
120 {
121 EditorGUILayout.Space();
122 EditorGUILayout.SelectableLabel("Version: " + ProceduralToolkitMenu.version + "\n" +
123 "Copyright © Daniil Basmanov\n" +
124 "Icon by Iuliana Koroviakovskaia", GUILayout.Height(50));
125
126 EditorGUILayout.Space();
127 if (GUILayout.Button("Repository"))
128 {
129 Application.OpenURL("https://github.com/Syomus/ProceduralToolkit/");
130 }
131 if (GUILayout.Button("Asset Store"))
132 {
133 Application.OpenURL("https://www.assetstore.unity3d.com/#!/content/16508");
134 }
135 if (GUILayout.Button("Issues"))
136 {
137 Application.OpenURL("https://github.com/Syomus/ProceduralToolkit/issues");
138 }
139 if (GUILayout.Button("Support email"))
140 {
141 Application.OpenURL("mailto:proceduraltoolkit@syomus.com");
142 }
143 }
144 }
145 }